package com.jsy.common.util.publicApi.mybatis;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApiKeyExample {
    public static void main(String[] args) {
        // 加载Spring配置
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ApiKeyService apiKeyService = context.getBean(ApiKeyService.class);

        // 创建API Key
        ApiKey apiKey = new ApiKey();
        apiKey.setAccessKey("AK-TEST-123456");
        apiKey.setSecretKeyHash("hashed-secret-key");
        apiKey.setAppName("Test Application");
        apiKey.setStatus(1);
        apiKeyService.createApiKey(apiKey);

        // 查询API Key
        ApiKey retrievedKey = apiKeyService.getApiKeyByAccessKey("AK-TEST-123456");
        System.out.println("Retrieved API Key: " + retrievedKey.getAppName());

        // 更新API Key
        retrievedKey.setDescription("Updated description");
        apiKeyService.updateApiKey(retrievedKey);

        // 删除API Key
        apiKeyService.deleteApiKey(retrievedKey.getId());
    }
}